package com.hh.tc.ui.todo.editItem

import android.os.Bundle
import com.hh.base.ui.BaseActivity
import com.hh.tc.R
import com.hh.tc.databinding.ActivityEditTodoItemBinding
import com.hh.tc.ui.todo.addItem.AddItemDialog

class EditTodoItemActivity : BaseActivity<EditTodoItemViewModel, ActivityEditTodoItemBinding>() {

    private var addItemDialog: AddItemDialog? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initObserve()
    }

    override fun getLayoutId(): Int = R.layout.activity_edit_todo_item

    private fun initObserve() {
        viewModel.addItemDialogStatus.observe(this) {
            it.getContentIfNotHandled()?.let { (open, item, listener) ->
                if (open) {
                    if (addItemDialog == null) {
                        addItemDialog = AddItemDialog(this)
                    }
                    addItemDialog?.show(item, listener)
                } else {
                    addItemDialog?.dismiss()
                }
            }
        }
    }
}